home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / language / embedded / 68hc11 / smallc11.arc / CC5.C < prev    next >
Text File  |  1988-05-31  |  1KB  |  55 lines

  1. #include <stdio.h>
  2. #include "ccdef.c"
  3.  
  4. extern    int    eof;
  5.  
  6. /*
  7. *    Small C ver. 2.0 wants gets to return a line without an
  8. *    end of line marker.  MSDOS wants to return a CR.
  9. *    Also this dumb beast chokes on TABS!
  10. *    SO... I trap out CR & LF and replace TAB with BLANK
  11. *    (*&#^%^*!&^#%$@&*#&* compiler !!)
  12. */
  13.  
  14. #include <stdio.h>
  15.  
  16. duanefgets(str, max, fp)
  17. char *str;
  18. int max;
  19. FILE *fp;
  20. {
  21.     int c;
  22.     char *cs;
  23.  
  24.     cs = str;
  25.     while((--max > 0) && (c = getc(fp)) != EOF)
  26.     {
  27.         if(( c == 0x0a ) || (c == 0x0d))
  28.         {
  29.             break;
  30.         }
  31.         else if (c == 0x09)
  32.         {
  33.             c = 0x20;
  34.             *cs++ = c;
  35.         }
  36.         else
  37.         {
  38.             *cs++ = c;
  39.         }
  40.     }
  41.     *cs = '\0';
  42.     return((c == EOF && cs == str) ? NULL : str);
  43. }
  44.  
  45. getarg(n, str, maxsz, argc, argv) int n; char *str; int maxsz, argc, *argv; {  char *dptr, *sptr; int cnt;
  46.   if ((n>(argc-1))|(n<0)) {str[0] = NULL; return EOF;}
  47.   cnt=0; dptr=str; sptr=argv[n];
  48.   while(*dptr++ = *sptr++) {
  49.     if(++cnt >= (maxsz-1))
  50.       {*dptr=NULL; break;}
  51.     }
  52.   return cnt;
  53. }
  54.  
  55. /************************ end of file cc5.c ******************************/